
// var api_host = 'https://api1.maxdoge.com';//测试环境
// var api_host = 'https://api.maxdoge.com';
var api_host = 'https://admin.jawanology.com';
var publiccode = 'ZGZvI1mi8Q';
var upyun_imgHost = "https://img.maxdoge.com";
var upyun_bucket = "yixunweixing";
var upyun_opterator = "yixunweixing";//又拍云空间操作员账户
var upyun_getSignUrl = api_host + "/api.php?ac=signupyun&publickey=" + publiccode;
                      
// let extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {};
// var appid = extConfig.appid;
// var orgid = extConfig.uid;
// var version = extConfig.version;
// var appType = extConfig.appType;


var appType = 1;//1、带销售功能小程序  2、不带销售功能小程序 3、服务类型企业小程序

// var version = "v3.6";
// var appid = "wx2dc763bf69b42c4b";
// var orgid = "11760";//鲜送达


// var version = "v1.0";
// var appid = "wxe424f7a0e7c36ee0";
// var orgid = "12758";//e家装

var version = "v1.0";
var appid = "wxb9594f7c085d78a5";
var orgid = "12809";//三江精品汇 正式环境


// var version = "v1.0";
// var appid = "wx4c9216357a5c815a";
// var orgid = "13115";//快夹脆 正式环境

// var version = "v1.0";
// var appid = "wx723bd493e8700417";
// var orgid = "14057";//美考达人 正式环境

// var version = "v1.0";
// var appid = "wx41aff492bfc67869";
// var orgid = "14361";//领亿来酒业 正式环境

// var version = "v1.0";
// var appid = "wxc80e1bb02ede8f48";
// var orgid = "14408";//湜安娜服饰 正式环境

// var version = "v1.0";
// var appid = "wx6d134c558971fad0";
// var orgid = "14439";//佛山车金融 正式环境

// var version = "v1.0";
// var appid = "wxa23cdb5947241e83";
// var orgid = "14562";//MM衣库 正式环境

// var version = "v1.0";
// var appid = "wx84e6551e9295df21";
// var orgid = "14568";//东和 正式环境

// var version = "v1.0";
// var appid = "wxfade47ccf78011aa";
// var orgid = "14924";//Dora衣尚 正式环境

// var version = "v1.0";
// var appid = "wxd56afa09ffcf53a7";
// var orgid = "14939";//繁花 正式环境

// var version = "v1.0";
// var appid = "wxf41bce7c838373a3";
// var orgid = "15671";//壹号人才 正式环境

// var version = "v1.0";
// var appid = "wx74654a73033cc08b";
// var orgid = "15844";//孔剑科技 正式环境

// var version = "v1.0";
// var appid = "wxe1b26454449220ae";
// var orgid = "15848";//广东车险汇 正式环境

// var version = "v1.0";
// var appid = "wx5254fbff0b27cc93";
// var orgid = "16535";//盛世长运sansemall 正式环境

// var version = "v1.0";
// var appid = "wx6cbffff84355637d";
// var orgid = "17784";//来报名 正式环境

// var version = "v1.0";
// var appid = "wx700a3d789bbdf1a6";
// var orgid = "18681";//奥卡鲜奶 正式环境

// var version = "v1.0";
// var appid = "wx65061100c745fac3";
// var orgid = "18535";//家家公寓 正式环境

//var version = "v1.0";
//var appid = "wxd75bc07b8c938bcd";
//var orgid = "19106";//森祖科技 正式环境


// var version = "v1.0";
// var appid = "	wx5bddae1ce9396769";
// var orgid = "21145";//  家家烘焙 正式环境

// var version = "v1.0";
// var appid = "wxd9ddede4fd883563";
// var orgid = "21398";//  尚品高級食材分銷商 正式环境

// var version = "v1.0";
// var appid = "wx2598b999abcde225";
// var orgid = "21780";//  测试小程序正式环境

function formatTime(date, day_join, time_join) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()

  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds()

  if (time_join) {
    return [year, month, day].map(formatNumber).join(day_join) + ' ' + [hour, minute, second].map(formatNumber).join(time_join)
  } else {
    return [year, month, day].map(formatNumber).join(day_join)
  }

}

function formatNumber(n) {
  n = n.toString()
  return n[1] ? n : '0' + n
}

function api(d){
  d.data.binduid = this.orgid;
  if(!d.data.publickey){
    d.data.publickey = this.publiccode;
  }
  if(!d.method) d.method="GET";
  console.log("请求参数：", d.data);
  var header = d.header ? d.header :{
      "Content-Type": "application/json" 
  };
  if (d.method == "POST" || d.method == "post") {
    d.data = json2Form(d.data);
    header = {
      "Content-Type": "application/x-www-form-urlencoded" 
    };
  }
  wx.request({
    url: api_host + "/api.php",
    method:d.method,
    data:d.data,
    success: function(responseData){
      if(responseData.statusCode == 200){
        d.success(responseData);
      }
    },
    header: header,  
    fail: function(e) {
      console.log(e);
    }
  });
}

function json2Form(json) {  
    var str = [];  
    for(var p in json){  
        str.push(encodeURIComponent(p) + "=" + encodeURIComponent(json[p]));  
    }  
    return str.join("&");  
}

module.exports = {
  formatTime: formatTime,
  formatNumber: formatNumber,
  api:api,
  json2Form:json2Form,
  publiccode:publiccode,
  api_host: api_host,
  upyun_bucket: upyun_bucket,
  upyun_imgHost: upyun_imgHost,
  upyun_opterator: upyun_opterator,
  // upyun_apikey: upyun_apikey,
  upyun_getSignUrl: upyun_getSignUrl,

  appid: appid,
  orgid: orgid,
  version: version,
  appType: appType,

}
